package push.tools.service.config.network;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class OkHttpClientConfig {
    private static final Logger logger = LoggerFactory.getLogger(OkHttpClientConfig.class);

    //超时时间
    private static final int TimeOut = 60;

    @Bean("OkHttpClient")
    public OkHttpClient okHttpClient() {
        logger.warn("----------->OkHttpClient初始化了<-----------");
        return new OkHttpClient.Builder()//
                .connectTimeout(TimeOut, TimeUnit.SECONDS)//连接超时时间
                .readTimeout(TimeOut, TimeUnit.SECONDS)//读取超时时间
                .writeTimeout(TimeOut, TimeUnit.SECONDS)//写入超时时间
                //.addInterceptor(new RetryInterceptor())//失败重试拦截器
                .build();
    }

    public static Request getRequest(String requestUrl) {
        return new Request.Builder().url(requestUrl).build();
    }
}
